package com.econvent.auth.service.impl;

import com.econvent.hrmreource.po.base.HrmResource;
import com.econvent.hrmreource.service.base.HrmResourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * Spring security 从数据库中加载用户的相关信息
 *
 * @author xiekun
 * @since 1.0
 */

@Component
@Slf4j
public class HrmResourceDetailService implements UserDetailsService {

    @Autowired
    HrmResourceService hrmResourceService ;

    /**
     * 根据userName查询对应的用户信息
     * **/
    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
        HrmResource hrmResource = hrmResourceService.findUserByLoginId(userName) ;
        if(hrmResource == null) {
            throw new UsernameNotFoundException("用户账号不存在:" + userName);
        }

        return null;
    }
}